home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
1833
/
1833.xpi
/
chrome
/
yoono.jar
/
content
/
yoono
/
bkmMenus.js
< prev
next >
Wrap
Text File
|
2009-12-16
|
8KB
|
218 lines
function log(m) {
var console = Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService);
console.logStringMessage(m);
}
// Get a locale string with his name
function _(name) {
return YOONO_DIALOGS.bundle.GetStringFromName(name);
}
// this method needs to be accessible in FF2 and FF3
yoonoGlob.createContext = function (destPopup, id, isFolder, isPrivate, isBookmark) {
var menu=destPopup.yoonoPopup;
// Ignore places top container (FF3)
if (!YOONO_BKM.getNode(id)) {
if (menu) {
try { destPopup.removeChild(menu); } catch(e) {}
}
return;
}
if (!menu || menu!=destPopup.lastChild /* <- FF2 */) {
log("create");
menu = document.createElement("menu");
menu.setAttribute("label", "Yoono");
menu.addEventListener("popupshowing", function (aEvent) {aEvent.stopPropagation()}, false);
menu.addEventListener("popuphidden", function (aEvent) {aEvent.stopPropagation()}, false);
destPopup.yoonoPopup=destPopup.appendChild(menu);
} else {
log("cleanup");
while(menu.firstChild)
menu.removeChild(menu.firstChild);
}
var menupopup = document.createElement("menupopup");
menu.appendChild(menupopup);
if (isFolder) {
var menuitem = document.createElement("menuitem");
if (isPrivate) {
menuitem.setAttribute("label", _("bkms.public.label"));
menuitem.setAttribute("accesskey", _("bkms.public.accesskey"));
menuitem.addEventListener("click", function (e) { bmMkPublic(id); }, false);
} else {
menuitem.setAttribute("label", _("bkms.private.label"));
menuitem.setAttribute("accesskey", _("bkms.private.accesskey"));
menuitem.addEventListener("click", function (e) { bmMkPrivate(id); }, false);
}
menupopup.appendChild(menuitem);
menuitem = document.createElement("menuitem");
menuitem.setAttribute("label", _("bkms.searchmultisite.label"));
menuitem.setAttribute("accesskey", _("bkms.searchmultisite.accesskey"));
menuitem.setAttribute("tooltiptext", _("bkms.searchmultisite.tooltiptext"));
menuitem.addEventListener("click", function (e) { searchSites(id); }, false);
menupopup.appendChild(menuitem);
menuitem = document.createElement("menuitem");
menuitem.setAttribute("label", _("bkms.random.label"));
menuitem.setAttribute("accesskey", _("bkms.random.accesskey"));
menuitem.setAttribute("tooltiptext", _("bkms.random.tooltiptext"));
menuitem.addEventListener("click", function (e) { randomFromFolder(e, id); }, false);
menupopup.appendChild(menuitem);
} else if (isBookmark) {
var menuitem = document.createElement("menuitem");
menuitem.setAttribute("label", _("bkms.searchsinglesite.label"));
menuitem.setAttribute("accesskey", _("bkms.searchsinglesite.accesskey"));
menuitem.setAttribute("tooltiptext", _("bkms.searchsinglesite.tooltiptext"));
menuitem.addEventListener("click", function (e) { searchSites(id); }, false);
menupopup.appendChild(menuitem);
}
}
function attachYoonoBkmMenu() {
try {
// FF3 specific
if (typeof PlacesController!="undefined") {
log("switch to ff3 bookmarks mode");
YOONO_LOG.debug("switch to ff3 bookmarks mode");
PlacesController.prototype.beforeYoonoBuildContextMenu = PlacesController.prototype.buildContextMenu;
PlacesController.prototype.buildContextMenu = function (aPopup) {
try {
var result = this.beforeYoonoBuildContextMenu(aPopup);
var node = this._view.selectedNode;
if ( node == null || (!PlacesUtils.nodeIsFolder(node) && !PlacesUtils.nodeIsBookmark(node)) )
return result;
yoonoGlob.createContext(aPopup, node.itemId, PlacesUtils.nodeIsFolder(node), YOONO_BKM.isPrivate(node.itemId), PlacesUtils.nodeIsBookmark(node));
return true;
} catch(e) {
log("e : "+e+" / "+e.stack);
alert(e);
YOONO_LOG.exception(e);
}
}
} else { // FF2 specific
YOONO_LOG.debug("switch to ff2 bookmarks mode");
// on l'accroche α BookmarksCommand car createContextMenu utilise une rΘfererence α 'this'
BookmarksCommand.createContextMenuBeforeYoono = BookmarksCommand.createContextMenu;
BookmarksCommand.createContextMenu = function (aEvent, aSelection, aDS) {
BookmarksCommand.createContextMenuBeforeYoono(aEvent, aSelection, aDS);
var popup = aEvent.target;
if (!popup.childNodes.length) return;
var rTarget = aSelection.item[0];
try {
var type = BookmarksUtils.resolveType(rTarget, aDS);
if (type != "Folder" && type != "PersonalToolbarFolder" && type != "Bookmark")
return;
} catch (ex) {}
log(aSelection+" / "+aSelection.item+" / "+aSelection.item.length+" | "+rTarget.Value+" : "+type+" ] "+popup.tagName);
yoonoGlob.createContext(popup, rTarget.Value, type=="Folder" || type=="PersonalToolbarFolder", YOONO_BKM.isPrivate(rTarget.Value), type=="Bookmark");
}
}
} catch(e) {
log("exp : "+e);
}
}
function markPrivateFolders() {
// FF3 specific
var menu=document.getElementById('bookmarksMenuPopup');
// FF2
if (!menu)
menu=document.getElementById('menu_BookmarksPopup');
menu.addEventListener("popupshowing", function () {
try {
function lock(node) {
node.className=node.className.replace(/ private/g,"");
if (
(node.node && node.node.itemId && YOONO_BKM.isPrivate(node.node.itemId)) // FF3
|| (node.id && YOONO_BKM.isPrivate(node.id)) // FF2
) {
node.className+=" private";
} else {
for(var i=0;i<node.childNodes.length;i++) {
lock(node.childNodes[i]);
}
}
}
lock(menu);
/* no longer available
var menuitem = document.getElementById("yoono-setroot-private");
if (YOONO_BKM.isPrivate(YOONO_BKM.getCurrentTree().getId())) {
menuitem.label = _("bkms.setrootpublic.label");
menuitem.setAttribute("accesskey" , _("bkms.setrootpublic.accesskey"));
menuitem.setAttribute("tooltiptext", _("bkms.setrootpublic.tooltiptext"));
menuitem.setAttribute("oncommand", "setRootPublic()");
} else {
menuitem.label = YOONO_DIALOGS.bundle.GetStringFromName("bkms.setrootprivate.label");
menuitem.setAttribute("accesskey" , _("bkms.setrootprivate.accesskey"));
menuitem.setAttribute("tooltiptext", _("bkms.setrootprivate.tooltiptext"));
menuitem.setAttribute("oncommand", "setRootPrivate()");
}
*/
} catch(e) {
YOONO_LOG.exception(e);
}
},false);
}
function setRootPrivate () {
YOONO_BKM.addToPrivateList(YOONO_BKM.getCurrentTree().getId());
}
function setRootPublic () {
YOONO_BKM.removeFromPrivateList(YOONO_BKM.getCurrentTree().getId());
}
function searchSites(id) {
return window.openDialog('chrome://yoono/content/dialogs/search.xul', 'search', 'chrome,modal', {node:YOONO_BKM.getNode(id)});
}
function bmMkPrivate (id) {
YOONO_BKM.addToPrivateList(id);
}
function bmMkPublic (id) {
YOONO_BKM.removeFromPrivateList(id);
}
function randomFromFolder(event, id) {
try {
YOONO_CMPT.addStat(['clic', 'foldersurprise', 'toolbar']);
YNPREFBRANCH.setCharPref('randomfolderid', id);
yoonoGlob.openUrlAccordingToPref('chrome://yoono/content/random.xul', event);
} catch(e) {
YOONO_LOG.exception(e);
}
}
function backupBkms() {
YOONO_BKM.backup();
}
function restoreBkms() {
window.openDialog('chrome://yoono/content/dialogs/restoreBkm.xul',
'yoono-bookmarks', 'chrome,modal');
}
///////////////////